package org.kolonitsky.alexey.flashui
{
  import flash.display.MovieClip;
  import flash.events.Event;
  import flash.events.MouseEvent;

  public class BtnSound extends MovieClip
  {

    private var volumeIcon: MovieClip

    private var muteIcon: MovieClip
    

    /** Constructor **/
    public function BtnSound() {
      super();
      useHandCursor = true
      buttonMode = true
      stop()
      addEventListener(Event.ADDED_TO_STAGE, init)
      addEventListener(MouseEvent.ROLL_OUT, onRollOut)
      addEventListener(MouseEvent.ROLL_OVER, onRollOver)
      addEventListener(MouseEvent.MOUSE_UP, onClick)
    }


    public function init (event:Event): void {
      volumeIcon = MovieClip(getChildByName("volumeIconMc"))
      volumeIcon.stop()
      volume = 0.50
      muteIcon = MovieClip(getChildByName("muteIconMc"))
      muteIcon.visible = _selected
    }
    
    public function onRollOut (event:MouseEvent): void {
      gotoAndStop("up")
    }
    
    public function onRollOver (event:MouseEvent): void {
      gotoAndStop("over")
    }
    
    public function onClick (event:MouseEvent): void {
      gotoAndStop("over")
      selected = !selected
    }

    /**
     * @property volume
     */
    private var _volume: Number

    public function get volume (): Number {
      return _volume
    }

    public function set volume (value:Number): void {
      if (value == _volume) return
      _volume = value
      if (value > 0.00 && value < 0.25) {volumeIcon.gotoAndStop(1)} else
      if (value > 0.25 && value < 0.50) {volumeIcon.gotoAndStop(2)} else
      if (value > 0.50 && value < 0.75) {volumeIcon.gotoAndStop(3)} else
      if (value > 0.75 && value < 1.00) {volumeIcon.gotoAndStop(4)}
    }


    /**
     * @property selected
     */
    private var _selected: Boolean = false

    public function get selected (): Boolean {
      return _selected
    }

    public function set selected (value:Boolean): void {
      _selected = value
      muteIcon.visible = value
    }

  }
}